Sort lexicographicallyΒΆ

Sort a string lexicographically.
def lexicographi_sort(S):
    return sorted(sorted(D), key=S.upper)

# test
print(lexicographi_sort('w3resource'))
print(lexicographi_sort('quickbrown'))

Output:

['3', 'c', 'e', 'e', 'o', 'r', 'r', 's', 'u', 'w']
['b', 'c', 'i', 'k', 'n', 'o', 'q', 'r', 'u', 'w']